var t = require("../../utils/config.js");

Page({
    data: {
        list: [],
        page: 1,
        isEnd: !1,
        url: "",
        type: ""
    },
    onLoad: function(a) {
        this.setData({
            type: a.type
        }), "day" == a.type ? (wx.setNavigationBarTitle({
            title: "日报历史"
        }), this.setData({
            url: t.urlList.API_WORK_REPORT_GET_DAILY_LIST
        })) : "week" == a.type ? (wx.setNavigationBarTitle({
            title: "周报历史"
        }), this.setData({
            url: t.urlList.API_WORK_REPORT_GET_Weekly_LIST
        })) : "month" == a.type && (wx.setNavigationBarTitle({
            title: "月报历史"
        }), this.setData({
            url: t.urlList.API_WORK_REPORT_GET_Monthly_LIST
        })), this.loadDataSource();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.data.page = 1, this.loadDataSource();
    },
    onReachBottom: function() {
        this.data.isEnd || (this.data.page++, this.loadDataSource());
    },
    onShareAppMessage: function() {},
    loadDataSource: function() {
        var t = this, a = wx.getStorageSync("userId"), e = wx.getStorageSync("serviceProviderId");
        1 == this.data.page && (t.setData({
            isEnd: !1
        }), t.data.list = []), wx.request({
            url: t.data.url,
            data: {
                page: this.data.page,
                rows: 10,
                userId: a,
                serviceProviderId: e
            },
            header: {
                "content-type": "application/json"
            },
            success: function(a) {
                t.setData({
                    list: t.data.list.concat(a.data.data)
                }), a.data.data.length < 10 && (t.data.page--, t.setData({
                    isEnd: !0
                })), wx.stopPullDownRefresh();
            }
        });
    },
    goToDetail: function(t) {
        var a = this, e = t.currentTarget.dataset.index, i = a.data.list[e];
        wx.navigateTo({
            url: "workReport?type=" + a.data.type + "&obj=" + JSON.stringify(i)
        });
    }
});